<?php
class Data_Model_HinhThucThiMapper extends Data_Model_DataMapperAbstract
{
	protected static $_instance = null;
	// dung de phan trang
	private $_paginator = null;
	
	public function searchById($id)
	{
		$db = $this->getDb();
		$selectHinhthucthi = $db->select()
								->from('tbl_hinhthucthi')
								->join('tbl_chitietlophoc','tbl_hinhthucthi.MaHinhThuc = tbl_chitietlophoc.MaHinhThuc')
								->where('tbl_hinhthucthi.MaHinhThuc = ?',$id);
		$hinhthucthi = $db->fetchRow($selectHinhthucthi);
	
		return $this->_populate($hinhthucthi);
	
	}
	public function hinhthucthiList()
	{
		$db = $this->getDb();
		$selectHinhthucthi = $db->select()
		->from('tbl_hinhthucthi');
		$hinhthucthis = $db->fetchAll($selectHinhthucthi);
	
		$hinhthucthiObjArray = array();
		foreach($hinhthucthis as $hinhthucthi)
		{
			$hinhthucthiObjArray[] = $this->_populate($hinhthucthi);
				
		}
		return $hinhthucthiObjArray;		
	}
	// hien thi
	public function _populate($data)
	{
		$obj = new Data_Model_HinhThucThi();
		$obj->setId($data['MaHinhThuc']);
		$obj->setHinhthucthi($data['HinhThucThi']);
		
		return $obj;
	}
	protected function _insert(Data_Model_DomainObjectAbstract $obj){
	
		$db = $this->getDb();
		$data = array(
				'MaHinhThuc' => $obj->getId(),
				'HinhThucThi' => $obj->gethinhthucthi()
				);
		$db->insert('tbl_hinhthucthi',$data);
	}
	protected function _update(Data_Model_DomainObjectAbstract $obj){
		
		$db = $this->getDb();
		$data = array(
				'MaHinhThuc' => $obj->getId(),
				'HinhThucThi' => $obj->gethinhthucthi()
		);
		$where = $db->quoteInto('MaHinhThuc = ?',$obj->getId());
		$db->update('tbl_hinhthucthi',$data,$where);
	}
	
	public function delete($id)
	{
		$db = $this->getDb();
		$where = $db->quoteInto('MaHinhThuc = ?',$id);
		$db->delete('tbl_hinhthucthi',$where);
	}
	
	// Goi chinh no
	
	public static function getInstance()
	{
		if(null === self::$_instance)
		{
			self::$_instance = new self();				
		}
		return self::$_instance;
	}
}